var app = angular.module('app', ['ui.router']);

app.filter('trusthtml', ['$sce', function($sce) {
    return function(text) {
        return $sce.trustAsHtml(text);
    };
}]);

app.run(['$location', '$rootScope', '$http', '$state', function($location, $rootScope, $http, $state) {
    $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
        $rootScope.title = 'ZFH的小站' + (toState.title ? ' - ' + toState.title : '');
        $rootScope.$state = $state;
        _hmt.push(['_trackPageview', '/#' + $location.path()]);
    });

}]);

app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.when('', '/index');
    $stateProvider.state('index', {
            url: '/index',
            title: '首页',
            views: {
                main: {
                    templateUrl: '/template/blog-list-first.html',
                    controller: 'indexCtrl',
                    controllerAs: 'vm'
                }
            }
        })
        .state('blog-list', {
            url: '/blog-list/:id',
            views: {
                main: {
                    templateUrl: '/template/blog-list.html',
                    controller: 'blogListCtrl',
                    controllerAs: 'vm'
                }
            }
        })
        .state('article', {
            url: '/article/:id',
            views: {
                main: {
                    templateUrl: '/template/article.html',
                    controller: 'articleCtrl',
                    controllerAs: 'vm'
                }
            }
        })
        .state('about', {
            url: '/about',
            views: {
                main: {
                    templateUrl: '/template/about.html',
                }
            }
        });
}]);